﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;
using System.Collections;
using System.Reflection;
using UMC.Wiki.Entities;
using UMC.Web;

namespace UMC.Wiki.Activities
{
    class SubjectPortfolioDelActivity : WebActivity
    {
        public override void ProcessActivity(WebRequest request, WebResponse response)
        {
            var sid = UMC.Data.Utility.UInt64Parse(this.AsyncDialog("Id", request.Model, "Portfolio"));

            var user = this.Context.Token.Identity();
            var Portfolios = new List<Portfolio>();
            var ids = new List<Guid>();


            var portfolio = DataFactory.Instance().Portfolio(sid.Value);
            if (portfolio != null)
            {
                var member = DataFactory.Instance().ProjectMember(portfolio.project_id.Value, user.Id.Value);

                if (member != null)
                {
                    switch (member.AuthType)
                    {
                        case WebAuthType.Admin:
                        case WebAuthType.User:
                            break;
                        default:
                            this.Prompt("您未有编辑此图文的权限");
                            break;
                    }

                }
                else
                {
                    this.Prompt("您未有编辑此图文的权限");
                }


                if (DataFactory.Instance().Subject(portfolio).Length == 0)
                {
                    DataFactory.Instance().Delete(portfolio);

                    this.Context.Send(new UMC.Web.WebMeta().Put("type", "Subject.Portfolio.Del").Put("Id", sid), false);
                    this.Prompt("移除成功");
                }
                else
                {
                    this.Prompt("存在文档，不可删除");
                }

            }

        }

    }
}